﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    internal class In_OutInfo_Service : IIn_OutInfo_Service
    {
        private IIn_OutInfoDal _outinfo;
        private IMapper _mapper;
        public In_OutInfo_Service(IIn_OutInfoDal outinfo, IMapper mapper)
        {
            _outinfo = outinfo;
            _mapper = mapper;
        }

        public async Task<int> AddInOutInfoAsync(int inOutPerson, int inOutState)
        {
            return await _outinfo.AddAsync(new InOutinfo 
            {
                InOutPerson = inOutPerson,
                InOutState = inOutState
            });
        }

        public async  Task<int> DeleteInOutInfoAsync(int id)
        {
            var data = await _outinfo.QueryAsync(id);
            return data == null ? -1 : await _outinfo.DeleteAsync(data);
        }

        public async  Task<int> EditInOutInfoAsync(int id, int inOutPerson, int inOutState)
        {
            var data = await _outinfo.QueryAsync(id);
            if (data == null)
                return -1;
            data.InOutPerson = inOutPerson;
            data.InOutState = inOutState;
            return await _outinfo.EditAsync(data);
        }

        public async  Task<List<In_OutInfoDto>> QueryInOutInfoAllAsync()
        {
            var data = await _outinfo.QueryAsync();
            return _mapper.Map<List<InOutinfo>, List<In_OutInfoDto>>(data);
        }

        public async  Task<In_OutInfoDto> QueryInOutInfoByIdAsync(int id)
        {
            var data = await _outinfo.QueryAsync(id);
            return _mapper.Map<InOutinfo, In_OutInfoDto>(data);
        }
    }
}
